package com.M10.BE.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

import com.M10.BE.entity.NAsset;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/8/8.
 */

public class TableAsset {

    public static void insertAsset(Context ctx, NAsset asset) {
        ContentValues cv = new ContentValues();
        cv.put(Constants.ASSET_CARDID, asset.getCardId());
        cv.put(Constants.ASSET_CNUM, asset.getCnum());
        cv.put(Constants.ASSET_INVENTORYID, asset.getInventoryID());
        cv.put(Constants.ASSET_LABELID, asset.getLabelId());
        cv.put(Constants.ASSET_LABELTYPE, asset.getLabelType());
        cv.put(Constants.ASSET_NAME, asset.getName());
        cv.put(Constants.ASSET_USEORG, asset.getUseOrg());
        cv.put(Constants.ASSET_ZCNO, asset.getZcNo());
        ctx.getContentResolver().insert(Constants.CONTENT_C_ASSET_URI, cv);
    }

    public static ArrayList<NAsset> searchAsset(Context ctx) {
        ArrayList<NAsset> result = new ArrayList<NAsset>();
        Cursor cursor = ctx.getContentResolver().query(Constants.CONTENT_C_ASSET_URI, null,
                null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            for (int i = 0; i < cursor.getCount(); i++) {
                NAsset asset = new NAsset();
                asset.setCardId(cursor.getString(cursor.getColumnIndex(Constants.ASSET_CARDID)));
                asset.setCnum(cursor.getString(cursor.getColumnIndex(Constants.ASSET_CNUM)));
                asset.setLabelId(cursor.getString(cursor.getColumnIndex(Constants.ASSET_LABELID)));
                asset.setLabelType(cursor.getString(cursor.getColumnIndex(Constants.ASSET_LABELTYPE)));
                asset.setName(cursor.getString(cursor.getColumnIndex(Constants.ASSET_NAME)));
                asset.setUseOrg(cursor.getString(cursor.getColumnIndex(Constants.ASSET_USEORG)));
                asset.setZcNo(cursor.getString(cursor.getColumnIndex(Constants.ASSET_ZCNO)));
                asset.setInventoryID(cursor.getString(cursor.getColumnIndex(Constants.ASSET_INVENTORYID)));
                result.add(asset);
            }
        }
        return result;
    }
}
